const { resolve } = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");


const entry = {
  main: resolve(__dirname, 'src', 'index.js'),
  second: resolve(__dirname, 'src', 'second.js'),
}

const output = {
  path: resolve(__dirname, 'build'),
  filename: '[name].js',
  clean: true,
}

const plugins = [
  new HtmlWebpackPlugin(),
  new MiniCssExtractPlugin({
    filename: 'style/[name].css'
  }),
]

const MODULE = {
  rules: [
    {
      test: /\.css$/, // 匹配以.css结尾的文件
      use: [MiniCssExtractPlugin.loader, {
        loader: 'css-loader',
        options: {
          modules: true
        }
      }, 'postcss-loader'], // 使用 css-loader 处理
    }
  ]
}

const optimization = {
  minimizer: [
    new CssMinimizerPlugin(),
  ],
}


module.exports = {
  entry, 
  output,
  plugins,
  module: MODULE,
  // optimization,
  mode: optimization ? 'production' : 'development',
}